<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>各工区报工及排产率查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'各工区报工及排产率查询报表'"></vue2-report-header>
    <div style="padding:5px 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="originalfactoryid">
          <el-select v-model="queryInfo.originalfactoryid" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="筛选时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-popover placement="top-start" title="报工数统计规则:" width="400" trigger="hover">
            <span slot="reference" class="el-icon-info"> 报工数</span>
            <p>1. 排除检验工序。</p>
            <p>2. 排除名称中包含【洗】【油】【库】这几个字的工序。</p>
            <p>3. 报工时间在所选时间范围内。</p>
          </el-popover>
        </el-form-item>

        <el-form-item>
          <el-popover placement="top-start" title="报工中已排产统计规则:" width="400" trigger="hover">
            <span slot="reference" class="el-icon-info"> 报工中已排产</span>
            <p>1. 排除检验工序。</p>
            <p>2. 排除名称中包含【洗】【油】【库】这几个字的工序。</p>
            <p>3. 报工时间在所选时间范围内。</p>
            <p>4. 报工前该工序已排产。</p>
          </el-popover>
        </el-form-item>

        <el-form-item>
          <el-popover placement="top-start" title="" width="400" trigger="hover">
            <span slot="reference" class="el-icon-info"> 排产率</span>
            <p>排产率 = 报工中已排产 ÷ 报工数</p>
          </el-popover>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handleSearch">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="handleExport">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="工区id" prop="workcenterid" v-if="false"></el-table-column>
        <el-table-column label="工区名称" prop="workcentername"></el-table-column>
        <el-table-column label="报工数" prop="reportqty"></el-table-column>
        <el-table-column label="报工中已排产" prop="stepplanqty"></el-table-column>
        <el-table-column label="排产率" prop="stapplanrate" sortable></el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-download" size="mini"
              @click="exportThisRowData(scope.row.workcentername)">
              导出
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        queryInfo: {
          selectdate: [],
          originalfactoryid: ''// 主制造分厂
        },
        total: 0,
        loading: false,
        loadingText: '',
        dataList: [],
        factoryList: [],
        rules: {
          selectdate: [{ required: true, message: '筛选时间不能为空!', trigger: 'change' }],
          originalfactoryid: [{ required: true, message: '请选择主制分厂', trigger: 'change' }],
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        //查询按钮
        async handleSearch() {
          this.$refs['queryInfoRef'].validate((valid) => {
            if (valid) {
              this.getData();
            } else {
              return this.$message.error('必填项不能为空');
            }
          })
        },
        async handleExport() {
          this.$refs['queryInfoRef'].validate((valid) => {
            if (valid) {
              this.getExportExcel();
            } else {
              return this.$message.error('必填项不能为空');
            }
          })
        },
        //查询数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/report/WorkreportAndPlanRateReport.ashx?action=getData',
            data: {
              type: 'getData',
              ...this.queryInfo
            }
          })
          this.loading = false;
          this.dataList = data;
          this.total = total;
        },
        //导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/report/WorkreportAndPlanRateReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        // 导出本行数据
        async exportThisRowData(workcentername) {
          const config = {
            url: '../handler/report/WorkreportAndPlanRateReport.ashx?action=exportWokcenterDetail',
            data: {
              type: 'exportWokcenterDetail',
              ...this.queryInfo,
              workcentername
            }
          }
          exportExcelData(config, this);
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.originalfactoryid = factoryid;
        const monday = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD');
        const sunday = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [monday, sunday];
      }
    })
  </script>
</body>

</html>